using System;
using UnityEngine;

public class ShowtimePoint : MonoBehaviour
{
	public Transform mTrans;

	private bool isDrag;

	private Vector2 dragDeta;

	public UIEventListener rotateAreaBtn;

	private float speed = 8f;

	private Vector3 dir;

	private float mag;

	private Quaternion lookRot;

	public bool setangleflag;

	public float angletime;

	private void Start()
	{
		mTrans = base.transform;
		UIEventListener uIEventListener = rotateAreaBtn;
		uIEventListener.onPress = (UIEventListener.BoolDelegate)Delegate.Combine(uIEventListener.onPress, new UIEventListener.BoolDelegate(OnPressArea));
		UIEventListener uIEventListener2 = rotateAreaBtn;
		uIEventListener2.onDrag = (UIEventListener.VectorDelegate)Delegate.Combine(uIEventListener2.onDrag, new UIEventListener.VectorDelegate(OnDragCam));
	}

	private void LateUpdate()
	{
		if (!isDrag)
		{
			if (setangleflag)
			{
				angletime += Time.deltaTime;
				if (angletime > 1f)
				{
					angletime = 0f;
					setangleflag = false;
				}
				dir = Vector3.zero - mTrans.position;
				mag = dir.magnitude;
				if (mag > 0.001f)
				{
					lookRot = Quaternion.LookRotation(dir);
					mTrans.rotation = Quaternion.Slerp(mTrans.rotation, lookRot, Mathf.Clamp01(speed * Time.deltaTime));
				}
			}
		}
		else
		{
			Transform transform = mTrans;
			Vector3 localEulerAngles = mTrans.localEulerAngles;
			float x = localEulerAngles.x;
			Vector3 localEulerAngles2 = mTrans.localEulerAngles;
			float y = localEulerAngles2.y;
			Vector3 localEulerAngles3 = mTrans.localEulerAngles;
			float y2 = Mathf.LerpAngle(y, localEulerAngles3.y + dragDeta.x * 3f, Time.deltaTime * 8f);
			Vector3 localEulerAngles4 = mTrans.localEulerAngles;
			transform.localRotation = Quaternion.Euler(x, y2, localEulerAngles4.z);
		}
	}

	public void OnDragCam(GameObject obj, Vector2 deta)
	{
		dragDeta = deta;
		isDrag = true;
	}

	public void OnPressArea(GameObject obj, bool press)
	{
		if (!press)
		{
			dragDeta = Vector2.zero;
			isDrag = false;
		}
	}
}
